package org.forum.data.initial;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.forum.domain.Forum;
import org.forum.domain.MainTopic;
import org.forum.domain.User;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class InitialDataInsert {
	
	public static Logger logger = LoggerFactory.getLogger(InitialDataInsert.class);
	
	public static void main(String args[]){

		Session session = HibernateUtil.getSession();
		Transaction tx = session.beginTransaction();
		//
		User user = new User();
		user.setIsAdministration(Boolean.TRUE);
		user.setUsername("wbb");
		user.setUserPass("aaa");
		user.setE_mail("758172047@qq.com");
		session.save(user);
		
		Forum forum = new Forum();
		if(logger.isDebugEnabled()){
			logger.debug("userId:" + user.getUserId());
		}
		forum.setAdministratorId(user.getUserId());
		forum.setIntroduction("最有影响力的论坛之一！");
		forum.setTitle("搞怪恶魔");
		forum.setClassification("news");
		forum.setOpenTime(new Date(System.currentTimeMillis()));
		forum.setNumberOfFollows(new Integer(0));
		Set<User> users_1 = new HashSet<>();
		users_1.add(user);
		forum.setUsers(users_1);
		//持久化时会添加主键
		session.save(forum);
		
		MainTopic announcement_1 = new MainTopic();
		announcement_1.setAddTime(new Date(System.currentTimeMillis()));
		announcement_1.setClassification("news");
		announcement_1.setEssay("每个在此论坛的人必须....");
		announcement_1.setIsAnnouncement(Boolean.TRUE);
		announcement_1.setForum(forum);
		announcement_1.setPublisherId(user.getUserId());
		announcement_1.setTitle("通知1");
		announcement_1.setWeekview(new Long(4));
		announcement_1.setUser(user);
		session.save(announcement_1);
		//
		if(logger.isDebugEnabled()){
			logger.debug("forumId:" + forum.getForumId());
		}
		MainTopic mainTopic_1 = new MainTopic();
		mainTopic_1.setAddTime(new Date(System.currentTimeMillis()));
		mainTopic_1.setClassification("news");
		mainTopic_1.setEssay("oh, it is incredible");
		mainTopic_1.setIsAnnouncement(Boolean.FALSE);
		mainTopic_1.setForum(forum);
		mainTopic_1.setPublisherId(user.getUserId());
		mainTopic_1.setTitle("Tump,the 45th president of the US!");
		mainTopic_1.setWeekview(new Long(0));
		mainTopic_1.setUser(user);
		session.save(mainTopic_1);
		
		MainTopic mainTopic_2 = new MainTopic();
		mainTopic_2.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_2.setClassification("news");
		mainTopic_2.setEssay("Today,thanksgiving day !");
		mainTopic_2.setIsAnnouncement(Boolean.FALSE);
		mainTopic_2.setForum(forum);
		mainTopic_2.setPublisherId(user.getUserId());
		mainTopic_2.setTitle("thanksgiving day");
		mainTopic_2.setWeekview(new Long(0));
		mainTopic_2.setUser(user);
		session.save(mainTopic_2);
		
		MainTopic mainTopic_3 = new MainTopic();
		mainTopic_3.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_3.setClassification("news");
		mainTopic_3.setEssay("bbc news play a neutral role!");
		mainTopic_3.setIsAnnouncement(Boolean.FALSE);
		mainTopic_3.setForum(forum);
		mainTopic_3.setPublisherId(user.getUserId());
		mainTopic_3.setTitle("bbc news's value");
		mainTopic_3.setWeekview(new Long(0));
		mainTopic_3.setUser(user);
		session.save(mainTopic_3);
		
		//
		User user_2 = new User();
		user_2.setIsAdministration(Boolean.TRUE);
		user_2.setUsername("dbg");
		user_2.setUserPass("aaa");
		user_2.setE_mail("dbg@qq.com");
		session.save(user_2);
		//
		Forum forum_2 = new Forum();
		if(logger.isDebugEnabled()){
			logger.debug("userId:" + user_2.getUserId());
		}
		forum_2.setAdministratorId(user_2.getUserId());
		forum_2.setIntroduction("实时金融数据");
		forum_2.setTitle("BBC—finance");
		forum_2.setClassification("finance");
		forum_2.setOpenTime(new Date(System.currentTimeMillis()));
		forum_2.setNumberOfFollows(new Integer(0));
		Set<User> users_2 = new HashSet<>();
		users_2.add(user_2);
		forum_2.setUsers(users_2);
		//持久化时会添加主键
		session.save(forum_2);
		
		//
		if(logger.isDebugEnabled()){
			logger.debug("forumId:" + forum_2.getForumId());
		}
		MainTopic mainTopic_4 = new MainTopic();
		mainTopic_4.setAddTime(new Date(System.currentTimeMillis()));
		mainTopic_4.setClassification("finance");
		mainTopic_4.setEssay("oh, it is incredible");
		mainTopic_4.setIsAnnouncement(Boolean.FALSE);
		mainTopic_4.setForum(forum_2);
		mainTopic_4.setPublisherId(user_2.getUserId());
		mainTopic_4.setTitle("Tump,the 45th president of the US!");
		mainTopic_4.setWeekview(new Long(0));
		mainTopic_4.setUser(user_2);
		session.save(mainTopic_4);
		
		MainTopic mainTopic_5 = new MainTopic();
		mainTopic_5.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_5.setClassification("finance");
		mainTopic_5.setEssay("Today,thanksgiving day !");
		mainTopic_5.setIsAnnouncement(Boolean.FALSE);
		mainTopic_5.setForum(forum_2);
		mainTopic_5.setPublisherId(user_2.getUserId());
		mainTopic_5.setTitle("thanksgiving day");
		mainTopic_5.setWeekview(new Long(0));
		mainTopic_5.setUser(user_2);
		session.save(mainTopic_5);
		
		MainTopic mainTopic_6 = new MainTopic();
		mainTopic_6.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_6.setClassification("finance");
		mainTopic_6.setEssay("bbc news play a neutral role!");
		mainTopic_6.setIsAnnouncement(Boolean.FALSE);
		mainTopic_6.setForum(forum_2);
		mainTopic_6.setPublisherId(user_2.getUserId());
		mainTopic_6.setTitle("bbc news's value");
		mainTopic_6.setWeekview(new Long(0));
		mainTopic_6.setUser(user_2);
		session.save(mainTopic_6);
		
		//
		User user_3 = new User();
		user_3.setIsAdministration(Boolean.TRUE);
		user_3.setUsername("tj");
		user_3.setUserPass("aaa");
		user_3.setE_mail("tj@qq.com");
		session.save(user_3);
		//
		Forum forum_3 = new Forum();
		if(logger.isDebugEnabled()){
			logger.debug("userId:" + user_3.getUserId());
		}
		forum_3.setAdministratorId(user_3.getUserId());
		forum_3.setIntroduction("体育在线");
		forum_3.setTitle("BBC—PE");
		forum_3.setClassification("PE");
		forum_3.setOpenTime(new Date(System.currentTimeMillis()));
		forum_3.setNumberOfFollows(new Integer(0));
		Set<User> users_3 = new HashSet<>();
		users_3.add(user_3);
		forum_3.setUsers(users_3);
		//持久化时会添加主键
		session.save(forum_3);
		
		//
		if(logger.isDebugEnabled()){
			logger.debug("forumId:" + forum_3.getForumId());
		}
		MainTopic mainTopic_7 = new MainTopic();
		mainTopic_7.setAddTime(new Date(System.currentTimeMillis()));
		mainTopic_7.setClassification("PE");
		mainTopic_7.setEssay("oh, it is incredible");
		mainTopic_7.setIsAnnouncement(Boolean.FALSE);
		mainTopic_7.setForum(forum_3);
		mainTopic_7.setPublisherId(user_3.getUserId());
		mainTopic_7.setTitle("Tump,the 45th president of the US!");
		mainTopic_7.setWeekview(new Long(0));
		mainTopic_7.setUser(user_3);
		session.save(mainTopic_7);
		
		MainTopic mainTopic_8 = new MainTopic();
		mainTopic_8.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_8.setClassification("PE");
		mainTopic_8.setEssay("Today,thanksgiving day !");
		mainTopic_8.setIsAnnouncement(Boolean.FALSE);
		mainTopic_8.setForum(forum_3);
		mainTopic_8.setPublisherId(user_3.getUserId());
		mainTopic_8.setTitle("thanksgiving day");
		mainTopic_8.setWeekview(new Long(0));
		mainTopic_8.setUser(user_3);
		session.save(mainTopic_8);
		
		MainTopic mainTopic_9 = new MainTopic();
		mainTopic_9.setAddTime(new Date(System.currentTimeMillis() + 100000));
		mainTopic_9.setClassification("PE");
		mainTopic_9.setEssay("bbc news play a neutral role!");
		mainTopic_9.setIsAnnouncement(Boolean.FALSE);
		mainTopic_9.setForum(forum_3);
		mainTopic_9.setPublisherId(user_3.getUserId());
		mainTopic_9.setTitle("bbc news's value");
		mainTopic_9.setWeekview(new Long(0));
		mainTopic_9.setUser(user_3);
		session.save(mainTopic_9);
		
		tx.commit();
		session.close();
	}
}
